package com.roseski.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import com.roseski.dto.GoodsResp;
import com.roseski.dto.ThemeReq;
import com.roseski.model.RoseskiGoods;
import com.roseski.service.RoseskiGoodsService;
import com.roseski.util.DateTimeUtil;
import com.roseski.util.MoneyUtil;

@RestController
@RequestMapping(value = "order/goods")
public class GoodsController {
	
	@Autowired
	RoseskiGoodsService roseskiGoodsService;
	
	@RequestMapping(value="listGoodsByThemeId")
	@ResponseBody
	public Map<String,List<GoodsResp>> listGoodsByThemeId(ThemeReq req){
		Map<String,List<GoodsResp>> map = new HashMap<String, List<GoodsResp>>();
		List<RoseskiGoods> list = roseskiGoodsService.listGoodsByThemeId(req.getThemeId());
		List<GoodsResp> ret = new ArrayList<GoodsResp>();
		for(RoseskiGoods goods : list) {
			GoodsResp goodsResp = new GoodsResp();
			goodsResp.setPId(goods.getGoodsId());
			goodsResp.setPImg(goods.getImgUrl());
			goodsResp.setPDescription(goods.getGoodsDesc());
			goodsResp.setPPrice(MoneyUtil.convertFenToYuan(goods.getPrice()));
			goodsResp.setPTitle(goods.getGoodsName());
			List<String> times = new ArrayList<String>();
			times.add(DateTimeUtil.formatToStr(goods.getLimitStartTime(), DateTimeUtil.DATE_FORMAT_YMD));
			times.add(DateTimeUtil.formatToStr(goods.getLimitEndTime(), DateTimeUtil.DATE_FORMAT_YMD));
			goodsResp.setPTimeRange(times);
			ret.add(goodsResp);
		}
		map.put("productionList", ret);
		return map;
	}

}
